
let host = `${window.location.protocol}//${window.location.host}`;
// 如果在 gh-pages 里面
if (/^\/amis-editor-demo/.test(window.location.pathname)) {
  host += '/amis-editor';
}
const base_url = `${process.env.REACT_APP_API_BASE}` || host;

const config: {
  base_url: string;
  result_code: number | string;
  default_headers: AxiosHeaders;
  request_timeout: number;
  headers: any;
} = {
  /**
   * api请求基础路径
   */
  base_url: base_url,
  /**
   * 接口成功返回状态码
   */
  result_code: 200,

  /**
   * 接口请求超时时间
   */
  request_timeout: 30000,

  /**
   * 默认接口请求类型
   * 可选值：application/x-www-form-urlencoded multipart/form-data
   */
  default_headers: 'application/json',
  headers: {}
};

if (process.env.NODE_ENV === 'development') {
  //填充Authorization头，以便调试接口
  if (process.env.REACT_APP_API_TOKEN) {
    config.headers.Authorization = process.env.REACT_APP_API_TOKEN;
  }
  if (process.env.REACT_APP_TENANT_ID) {
    config.headers['tenant-id'] = process.env.REACT_APP_TENANT_ID;
  }
}
export {config};
